/*
 * @copyright IMTT. Co. Ltd.
 * 
 * Here is detailed comment.
 */
package com.apis.web.goods;

import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.apis.bussiness.entity.impl.GoodsImpl;
import com.apis.bussiness.entries.impl.GoodsMgrImpl;
import com.apis.web.Action;
import com.apis.web.WebConstants;
import com.apis.web.XmlResponse;


/**
 * @author LiHongChun
 * @date 2012-10-25
 * @copyright IMTT. Co. Ltd.
 */
public class UpdateGoods extends Action {

	/* (non-Javadoc)
	 * @see com.imtt.insect.web.Action#execute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void execute(HttpServletRequest req, HttpServletResponse resp) {
		// TODO Auto-generated method stub
		String name = req.getParameter("goods-name");
		String code = req.getParameter("goods-code");
		float price = Float.parseFloat( req.getParameter("goods-price"));
		String desc = req.getParameter("goods-desc");
		String typeId = req.getParameter("type-id");
		
		XmlResponse xml = new XmlResponse();
		xml.setRequest(Request(req));
		Integer id = Integer.parseInt( req.getParameter(WebConstants.TAG_GOODS_ID) );
		if (id == null) {
			String reason = "操作失败: 缺少必要信息导致当前操作失败...";
			xml.setReason(reason);
		} else {
			GoodsMgrImpl manager = new GoodsMgrImpl();
			GoodsImpl goods = (GoodsImpl) manager.get(GoodsImpl.class, id);
			goods.setName(name);
			goods.setCode(code);
			goods.setPrice(price);
			goods.setDescription(desc);
			//goods.setType(type);
			try {
				manager.update(goods);
				xml.setState(1);
			} catch (IllegalArgumentException e) {
				String reason = "操作失败...";
				xml.setReason(reason);
				xml.setException(e);
			}
		}

		Response(resp, xml.toString());
	}

	/* (non-Javadoc)
	 * @see com.imtt.insect.web.Action#getActionID()
	 */
	@Override
	public int getActionID() {
		// TODO Auto-generated method stub
		return 1003;
	}

}
